package com.kgc.scd.consumer;

import com.kgc.scd.contant.ArrivalRemindConstant;
import com.kgc.scd.contant.SeckillConstant;
import com.kgc.scd.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created On : 2022/6/8.
 * <p>
 * Author     : 98730
 * <p>
 * Description: 生成订单消息队列监听
 */
@Slf4j
@Component
public class TradeOrderPayListener {

    @Autowired
    private RedisUtils redisUtils;

    @JmsListener(destination = SeckillConstant.SECKILL_PAY_RESULT_QUEUE_NAME)
    @SendTo(SeckillConstant.SECKILL_SECKILL_RESP_QUEUE_NAME)
    public String saveTradeOrderFromQueue(Map<String,String> resultMap){
        log.info("+++++++ 收到订单支付结果，开始更新订单状态 ++++++");

        // 模拟订单状态的改变，将redis中订单状态改为1，已支付
        redisUtils.set(resultMap.get("out_trade_no"),1);

        return "收到订单支付结果，更新订单状态成功";
    }
}
